package com.itheima.web.controller;

import com.itheima.entity.BookMessageConstant;
import com.itheima.entity.CodeConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Student;
import com.itheima.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.awt.print.Book;
import java.util.List;

/**
 * @author ChaunceyZhang
 * @date 2022-10-22 00:19
 * @blog1 https://zephyr-cyber.github.io/
 * @blog2 https://www.yuque.com/gougougou-xwscx
 */
@RestController
@RequestMapping("/student")
public class ListController {

    @Autowired
    private StudentService service;
    @GetMapping
    public Result findAll() {
        List<Student> bookServiceAll = service.findAll();
        return Result.success(CodeConstant.GET_OK, BookMessageConstant.BOOK_QUERY_OK, bookServiceAll);
    }


    @PostMapping
    public Result save(@RequestBody Student student) {
        Boolean save = service.save(student);
        return Result.success(CodeConstant.SAVE_OK, BookMessageConstant.BOOK_SAVE_OK, null);
    }


    @GetMapping("/{id}")
    public Result fingById(@PathVariable("id") Integer id) {
        Book bookServiceById = service.findById(id);
        return Result.success(CodeConstant.GET_OK, BookMessageConstant.BOOK_QUERY_OK, bookServiceById);
    }

    @PutMapping
    public Result update(@RequestBody Student student) {
        Boolean update = service.update(student);
        return Result.success(CodeConstant.UPDATE_OK, BookMessageConstant.BOOK_UPDATE_OK, null);
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Integer id) {
        Boolean delete = service.delete(id);
        return Result.success(CodeConstant.DELETE_OK, BookMessageConstant.BOOK_DELETE_OK, null);
    }

}
